#pragma once

#include <linux/rwbase_rt.h>

struct rw_semaphore
{
    struct rwbase_rt rwbase;
};

#define __RWSEM_INITIALIZER(name)             \
    {                                         \
        .rwbase = __RWBASE_INITIALIZER(name), \
    }

#define DECLARE_RWSEM(lockname) \
    struct rw_semaphore lockname = __RWSEM_INITIALIZER(lockname)

/*
 * release a read lock
 */
extern void up_read(struct rw_semaphore *sem);
int down_read_killable(struct rw_semaphore *sem);
void down_read(struct rw_semaphore *sem);

/*
 * lock for writing
 */
extern void down_write(struct rw_semaphore *sem);

void up_write(struct rw_semaphore *sem);

void __init_rwsem(struct rw_semaphore *rwsem, const char *name,
                  struct lock_class_key *key);

#define init_rwsem(sem)                     \
    do                                      \
    {                                       \
        static struct lock_class_key __key; \
                                            \
        __init_rwsem((sem), #sem, &__key);  \
    } while (0)
